﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace diyCtrl
{
    public partial class UserControl1 : UserControl
    {

        //private string _searchText;

        //public string SearchText
        //{
        //    get
        //    {
        //        return this._searchText;
        //    }
        //    set
        //    {
        //        this._searchText = value;
        //    }
        //}


        /// <summary>
        /// 自定义控件，添加一个属性
        /// </summary>
        [Browsable(true), Category("Other"),DefaultValue("输入搜索条件")]
        public string SearchText
        {
            get => textBox1.Text;
            set => textBox1.Text = value;
        }

        [Browsable(true), Category("Other")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public override string Text { 
            get => textBox1.Text; 
            set => textBox1.Text = value; 
        }

        public UserControl1()
        {
            InitializeComponent();
        }

        //定义委托
        public delegate void BtnClickHandle(object sender, EventArgs e);
        //定义事件
        public event BtnClickHandle SearchEvent;

        /// <summary>
        /// 自定义事件的具体的实现
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl1_Click(object sender, EventArgs e)
        {
            SearchEvent(sender, e);
        }

        /// <summary>
        /// 属性的值，是通过textBox1来填充的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.SearchText = textBox1.Text;
        }
    }
}
